import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'
import viteCompression from 'vite-plugin-compression';


export default ({mode})=> {

  const isPro = mode === 'production';

  return defineConfig({
    base: "/",
    build: {
      minify: "terser",
      terserOptions: {
        compress: {
          drop_console: isPro
        }
      }
    },
    server:{
      allowedHosts: ["maxtang.cc","money.medicine.mzdykj.com","banana.medicine.mzdykj.com"]
    },
    plugins: [
      vue(),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/client/components/SvgIcon/icons')],
        symbolId: 'icon-[name]'
      }),
      isPro?viteCompression():null,
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src/client', import.meta.url))
      }
    },
    css: {
      preprocessorOptions: {
          scss: {
              additionalData: `@use "@/style/mixin.scss" as *;`,
              api: 'modern-compiler'
          }
      }
    }
  })
}


